package com.yanqu.road.server.cmd.cricket;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cricket.CricketProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.cricket.CricketModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：xx
 */
@Cmd(code = GameProtocol.S_CRICKET_SKILL_UP, desc = "升级基恩能")
public class CricketSkillUpCmd extends AbstractCommand {
    private int cricketId;
    private int skillId;
    private int goodsIndex;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CricketProto.CricketSkillUpReqMsg msg = CricketProto.CricketSkillUpReqMsg.parseFrom(packet.getBytes());
        cricketId = msg.getCricketId();
        skillId = msg.getSkillId();
        if (msg.hasIndex()) {
            goodsIndex = msg.getIndex();
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(CricketModule.class).skillUp(cricketId, skillId, goodsIndex);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            CricketProto.CricketSkillUpRespMsg.Builder respMsg = CricketProto.CricketSkillUpRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_CRICKET_SKILL_UP, respMsg);
        }
    }
}
